package com.ruoyi.game.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.game.domain.GoldCoinRecord;
import com.ruoyi.game.service.IGoldCoinRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 金币记录Controller
 *
 * @author 小胖
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/record")
public class GoldCoinRecordController extends BaseController
{
    @Autowired
    private IGoldCoinRecordService goldCoinRecordService;

    /**
     * 查询金币记录列表
     */
    @RequiresPermissions("system:record:list")
    @GetMapping("/list")
    public TableDataInfo list(GoldCoinRecord goldCoinRecord)
    {
        startPage();
        List<GoldCoinRecord> list = goldCoinRecordService.selectGoldCoinRecordList(goldCoinRecord);
        return getDataTable(list);
    }

    /**
     * 导出金币记录列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "金币记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoldCoinRecord goldCoinRecord)
    {
        List<GoldCoinRecord> list = goldCoinRecordService.selectGoldCoinRecordList(goldCoinRecord);
        ExcelUtil<GoldCoinRecord> util = new ExcelUtil<GoldCoinRecord>(GoldCoinRecord.class);
        util.exportExcel(response, list, "金币记录数据");
    }

    /**
     * 获取金币记录详细信息
     */
    @RequiresPermissions("system:record:query")
    @GetMapping(value = "/{goldCoinId}")
    public AjaxResult getInfo(@PathVariable("goldCoinId") Long goldCoinId)
    {
        return AjaxResult.success(goldCoinRecordService.selectGoldCoinRecordByGoldCoinId(goldCoinId));
    }

    /**
     * 新增金币记录
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "金币记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoldCoinRecord goldCoinRecord)
    {
        return toAjax(goldCoinRecordService.insertGoldCoinRecord(goldCoinRecord));
    }

    /**
     * 修改金币记录
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "金币记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoldCoinRecord goldCoinRecord)
    {
        return toAjax(goldCoinRecordService.updateGoldCoinRecord(goldCoinRecord));
    }

    /**
     * 删除金币记录
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "金币记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goldCoinIds}")
    public AjaxResult remove(@PathVariable Long[] goldCoinIds)
    {
        return toAjax(goldCoinRecordService.deleteGoldCoinRecordByGoldCoinIds(goldCoinIds));
    }
}
